﻿using System;
using System.Linq.Expressions;

namespace FutureTech.ComponentModel
{
        /// <summary>
        /// 提供属性更改通知对象的扩展方法
        /// </summary>
        public static class NotifyPropertyChangedObjectExtensions
        {
                /// <summary>
                /// 通知对象属性已改变
                /// </summary>
                /// <typeparam name="T">对象类型</typeparam>
                /// <typeparam name="TProperty">对象属性</typeparam>
                /// <param name="notifyPropertyChangedObject">属性改变的对象</param>
                /// <param name="expression">获取对象属性的Lambda表达式</param>
                public static void NotifyPropertyChanged<T, TProperty>(this　T notifyPropertyChangedObject, Expression<Func<T, TProperty>> expression) where T : NotifyPropertyChangedObject
                {
                        var memberExpression = expression.Body as MemberExpression;
                        if (memberExpression != null)
                        {
                                string propertyName = memberExpression.Member.Name;
                                notifyPropertyChangedObject.RaisePropertyChanged(propertyName);
                        }
                }
        }
}